// ActionScript file
import com.helloniu.fl.NCHandler;
import com.helloniu.fl.NSHandler;
import com.helloniu.fl.SOHandler;
import com.helloniu.fl.util.Tool;
import com.helloniu.fl.util.StyleTool;

private var ncHandler:NCHandler = null;
private var soHandler:SOHandler = null;
private var _userID:String;

private var playVideoW:Number = 110;
private var playVideoH:Number = 110;

private var playHandler:NSHandler;
private var playStreamName:String = null;
private var playUserID:String = null;

public function initConnection(ancHandler:NCHandler, asoHandler:SOHandler, auserID:String):void {
	this.ncHandler = ancHandler;
	this.soHandler = asoHandler;
	this._userID = auserID;
}

public function setPlayStreamName(aplayStreamName:String):void {
	playStreamName = aplayStreamName;
    
	playVideoBtn.enabled = playStreamName != null;
}

public function getPlayStreamName():String {
	return this.playStreamName;
}

public function setPlayUserID(aplayUserID:String):void {
	playUserID = aplayUserID;
}

public function getPlayUserID():String {
	return this.playUserID;
}

private function playVideo(e:*):void {    
	if(playStreamName == null) {
    	return;
    }

	if(!playVideoBtn.selected) {
    	if(playHandler != null) {
        	playHandler.closeStream();
        }

    	return;
    }

	vdShow.width = playVideoH;
	vdShow.height = playVideoH;

	playHandler = new NSHandler(ncHandler.getNC());
	playHandler.setStreamName(playStreamName);
    playHandler.setStartPlayFunc(startPlayFunc);
	playHandler.play();
    
	var video:Video = new Video();
	video.width = playVideoW;
	video.height = playVideoH;
	video.attachNetStream(playHandler.getStream());

	vdShow.addChild(video);
}

private function startPlayFunc(aplayHandler:NSHandler):void {
   Tool.traceT(aplayHandler.getStreamName() + ":play OK");
}

private function initApp(e:*):void {
	playVideoBtn.enabled = false;    
    StyleTool.setBtnStyle(playVideoBtn, "openVideoIcon");
    StyleTool.setBtnSStyle(playVideoBtn, "closeVideoIcon");
}